package com.NetWork.lesson3;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;

//消息发送方
public class UdpSend {
    public static void main(String[] args) throws Exception {

        DatagramSocket socket = new DatagramSocket(8888);
        //准备数据： 从控制台读取
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while(true) {//循环发送
            String data = br.readLine();//一行一行读
            byte[] buffer = data.getBytes();//必须转字节
            DatagramPacket packet = new DatagramPacket(buffer, 0, buffer.length, new InetSocketAddress("localhost", 7777));
            socket.send(packet);
            if (data.equals("q")){
                break;
            }
        }
        socket.close();
    }
}

    